/*
* @Author: z.p
* @Project: Zdotp
* @Date: 2025年01月18日
* @Description: 管理网络包的handler
*/

using Google.Protobuf;
using Zdotp.Actor;
using Zdotp.Actor.Kcp;
using Zdotp.Pb;

namespace Zdotp.Net.NetMessageHandler;

public interface IMessageHandler
{
    void Handle(ActorKcp kcpActor, uint sessionId, byte[] netMessage);
}
public abstract class KcpMessageHandler<T> : IMessageHandler where T : IMessage<T>, new()
{
    public void Handle(ActorKcp kcpActor, uint sessionId, byte[] netMessage)
    {
        var message = netMessage.Deserialize<T>();

        if (message is null) return;
        Run(kcpActor, kcpActor.MyActorSystem, sessionId, message);
    }

    protected abstract void Run(ActorKcp kcpActor, ActorSystem system, uint sessionId, T netMessage);
}